package com.vito.dcs.ProjectOverview.action;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vito.base.authoriza.action.BaseAction;
import com.vito.base.model.DataGrid;
import com.vito.base.model.ResMsg;
import com.vito.base.model.Result;
import com.vito.dcs.projectOverview.model.ProjectOverviewModel;
import com.vito.dcs.projectOverview.model.ProjectPileKeyModel;
import com.vito.dcs.projectOverview.service.ProjectOverviewService;
import com.vito.dcs.projectOverview.service.ProjectPileKeyService;
import com.vito.dcs.tendersOverview.Service.PileGpsService;
import com.vito.dcs.tendersOverview.model.PileGpsModel;

/**
 * 
 * 
 * @author zsk
 * @date 2019年4月23日  
 * @version 
 * @Description 项目概况项目进度比例
 *
 */
@Controller
@RequestMapping("/dcs/projectOverviewAction")
public class ProjectOverviewAction extends BaseAction{

	private static final Logger log = LoggerFactory.getLogger(ProjectOverviewAction.class);


	@Reference
	private ProjectOverviewService projectOverviewServiceImpl;

	@Reference
	private ProjectPileKeyService projectPileKeyServiceImpl;
	
	@Reference
	private PileGpsService pileGpsServiceImpl;

	/**
	 * 
	 * @author zsk
	 * @date 2019年4月23日  
	 * @version 
	 * @Description 根据项目编号，获取对应计划总量，和各个标段下完成量 （暂时无用）
	 *
	 */
	/*@RequestMapping("/getProjectProgress")
	@ResponseBody
	public Result getProjectProgress(ProjectOverviewModel projectOverviewModel){
		Result result = new Result();
		if(projectOverviewModel.getProjectNo() != null && !"".equals(projectOverviewModel.getProjectNo())){
			try{
				//根据项目id获取计划总量
				ProjectOverviewModel total = projectOverviewServiceImpl.getProjectPlanTotal(projectOverviewModel);
				projectOverviewModel.setTotal(total.getTotal());
				//根据项目id获取标段完成量
				ProjectOverviewModel completed = projectOverviewServiceImpl.getProjectCompletedTotal(projectOverviewModel);
				projectOverviewModel.setCompleted(completed.getCompleted());
				result.setCode(Result.CODE_OK);
				result.setData(projectOverviewModel);
			}catch(Exception ex){
				log.error("查询失败",ex);
				result.setCode(Result.CODE_ERROR);
				result.setMsg(ResMsg.EXECERR);
			}
		}else{
			log.error("查询失败","------项目编号为NULL-----");
			result.setCode(Result.CODE_ERROR);
			result.setMsg(ResMsg.EXECERR);
		}
		return result;
	}*/
	/**
	 * @author zsk
	 * @date 2019年4月25日  
	 * @version v1.0
	 * @Description  根据项目ID 获取标段
	 */
	@RequestMapping("/getPileKeyList")
	@ResponseBody
	public Result getPileKeyList(String pid){
		Result result = new Result();
		if(pid != null && !"".equals(pid)){
			try{
				//调用获取标段
				List<ProjectPileKeyModel> list = projectPileKeyServiceImpl.getProjectPileKeyList(pid);
				/*if(list.size() > 0){//查询成功
					result.setCode(Result.CODE_OK);
					result.setData(list);
				}*/
				result.setCode(Result.CODE_OK);
				result.setData(list);
			}catch(Exception ex){
				log.error("查询失败",ex);
				result.setCode(Result.CODE_ERROR);
				result.setMsg(ResMsg.EXECERR);
			}
		}else{
			log.error("查询失败","-项目ID为空-");
			result.setCode(Result.CODE_ERROR);
			result.setMsg(ResMsg.EXECERR);
		}
		return result;
	}

	/**
	 * @author zsk
	 * @date 2019年5月5日
	 * @version v1.0
	 * @Description  根据标段ID获取片区
	 */
	@RequestMapping("/getSectionIdAreaList")
	@ResponseBody
	public Result getSectionIdAreaList(String sectionId){
		Result result = new Result();
		if(sectionId != null && !"".equals(sectionId)){
			try{
				//调用获取标段
				List<ProjectPileKeyModel> list = projectPileKeyServiceImpl.getSectionIdAreaList(sectionId);
				result.setCode(Result.CODE_OK);
				result.setData(list);
			}catch(Exception ex){
				log.error("查询失败",ex);
				result.setCode(Result.CODE_ERROR);
				result.setMsg(ResMsg.EXECERR);
			}
		}else{
			log.error("查询失败","-项目ID为空-");
			result.setCode(Result.CODE_ERROR);
			result.setMsg(ResMsg.EXECERR);
		}
		return result;
	}
	/**
	 * 
	 * @author zsk
	 * @date 2019年4月25日  
	 * @version v1.0
	 * @Description 根据标段ID获取全部桩号
	 */
	@RequestMapping("/getAllPileKey")
	@ResponseBody
	public Result  getAllPileKey(PileGpsModel pileGpsModel){
		Result result = new Result();
		try {
			if(pileGpsModel.getSectionId() != null && !"".equals(pileGpsModel.getSectionId())){
				 List<PileGpsModel> data = pileGpsServiceImpl.getAllPileKey(pileGpsModel);
				 result.setCode(Result.CODE_OK);
				 result.setData(data);
			}else{
				result.setCode(Result.CODE_OK);
				result.setData(null);
			}
		} catch (Exception e) {
			log.error("查询失败",e);
			result.setCode(Result.CODE_ERROR);
			result.setMsg(ResMsg.EXECERR);
		}
		
		return result;
	}
}
